import type { TableColumn } from '@/framework/components/core/super-table';
import dayjs from 'dayjs';
import { i18n } from '@/locales';
import AsyncSelect from '@/components/search-header/async-select.vue';
import { getWordAssociative } from '@/api/common/common_data';
import { shallowRef } from 'vue';
export type TableListItem = {
  id: string;
  optCode: number;
  createTime: string;
  creatorName: string;
  stockUserName: string;
  title: string;
  specimenSerial: string;
  stockSerial: string;
};
export type TableColumnItem = TableColumn<TableListItem>;

// 库存编号
const typeMap = {
  1003: '样本出库',
  1004: '提醒处理',
  1005: '样本入库',
  1006: '样本移库',
  1008: '样本核销',
};
export const baseColumns: TableColumnItem[] = [
  {
    // @ts-ignore
    title: i18n.global.t('specimen.original_serial'),
    field: 'specimenSerial',
    formItemProps: {
      component: shallowRef(AsyncSelect),
      componentProps: {
        fetchData: async (params) => {
          const res = await getWordAssociative('specimen_original_serial', params, 5);
          return res.result.map((item) => ({
            label: item,
            value: item,
          }));
        },
      },
    },
    hideInTable: true,
  },
  {
    title: '库存编号',
    field: 'stockSerial',
    formItemProps: {
      component: shallowRef(AsyncSelect),
      componentProps: {
        fetchData: async (params) => {
          const res = await getWordAssociative('stock_serial', params, 5);
          return res.result.map((item) => ({
            label: item,
            value: item,
          }));
        },
      },
    },
    hideInTable: true,
  },
  {
    type: 'seq',
    title: '序号',
    width: 60,
  },
  {
    title: '操作类型',
    field: 'optCode',
    formatter: ({ cellValue }) => {
      return cellValue ? typeMap[cellValue] : '-';
    },
    hideInSearch: true,
  },
  {
    title: '操作时间',
    field: 'createTime',
    formatter: ({ cellValue }) => {
      return cellValue ? dayjs(cellValue).format('YYYY-MM-DD HH:mm:ss') : '-';
    },
    hideInSearch: true,
  },
  {
    // @ts-ignore
    title: i18n.global.t('common.manager'),
    field: 'creatorName',
    hideInSearch: true,
  },
  {
    title: '业务相关人员',
    field: 'stockUserName',
    hideInSearch: true,
  },
  {
    title: '操作描述',
    field: 'title',
    hideInSearch: true,
  },
];
